package com.work.biz.controller;

import java.util.List;

import com.work.mp.service.impl.MpTokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.work.common.annotation.Log;
import com.work.common.core.controller.BaseController;
import com.work.common.core.domain.AjaxResult;
import com.work.common.enums.BusinessType;
import com.work.biz.domain.BizClazz;
import com.work.biz.service.IBizClazzService;

/**
 * 班级Controller
 *
 * @author lee
 * @date 2021-04-22
 */
@RestController
@RequestMapping("/api/biz/clazz")
@Api(value = "班级api", tags = {"添加班级,班级查询接口"})
public class BizClazzController extends BaseController {
    @Autowired
    private IBizClazzService ibizClazzService;

    @Autowired
    private MpTokenService tokenService;

    /**
     * 查询所有班级
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询所有班级", httpMethod = "GET", notes = "成功：0，验证失败：500")
    public AjaxResult list(
            @ApiParam(value = "用户token", required = true)
            @RequestHeader("tk")
                    String tk
    ) {
        BizClazz bizClazz = new BizClazz();
        List<BizClazz> list = ibizClazzService.selectBizClazzList(bizClazz);
        return AjaxResult.success(list);
    }

    /**
     * 查询我管理的班级
     */
    @GetMapping("/myClassList")
    @ApiOperation(value = "查询用户管理的所有班级", httpMethod = "GET", notes = "成功：0，验证失败：500")
    public AjaxResult myClassList(
            @ApiParam(value = "用户token", required = true)
            @RequestHeader("tk")
                    String tk) {
        List<BizClazz> list = ibizClazzService.selectBizClazzListByTeacher(tokenService.getUserId(tk));
        return AjaxResult.success(list);
    }

    /**
     * 获取班级详细信息
     */
    @GetMapping(value = "/{classId}")
    public AjaxResult getInfo(@PathVariable("classId") Long classId) {
        return AjaxResult.success(ibizClazzService.selectBizClazzById(classId));
    }

    /**
     * 新增班级
     */
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation(value = "新建班级", httpMethod = "POST", notes = "成功：0，验证失败：500")
    public AjaxResult add(
            @ApiParam(value = "用户token", required = true)
            @RequestHeader("tk")
                    String tk,
            @ApiParam(value = "班级数据", required = true)
            @RequestBody BizClazz bizClazz) {
        bizClazz.setTeacherId(tokenService.getUserId(tk));
        return toAjax(ibizClazzService.insertBizClazz(bizClazz));
    }

    /**
     * 修改班级
     */
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizClazz bizClazz) {
        return toAjax(ibizClazzService.updateBizClazz(bizClazz));
    }

    /**
     * 删除班级
     */
    @Log(title = "班级", businessType = BusinessType.DELETE)
    @DeleteMapping("/{classIds}")
    public AjaxResult remove(@PathVariable Long[] classIds) {
        return toAjax(ibizClazzService.deleteBizClazzByIds(classIds));
    }
}
